package checkers3d.logic;

/**
 * Provides common functionality required by different board objects.
 *
 * @author Ruben Acuna
 */
public class UtilBoardObject
{
    /**
     * Checks if a PlayingSurfacePosition contains any objects which are
     * 'blocking' and returns the appropriate boolean.
     *
     * @param position A position to check.
     * @return Boolean indicating if position is blocked.
     */
    static public boolean isPositionBlocked(PlayingSurfacePosition position)
    {
        boolean blocked = false;

        for(IBoardObject object : position.getPositionObjects())
        {
            if(object.isBlocking())
            {
                blocked = true;
                break;
            }
        }

        return blocked;
    }

    /**
     * Checks if a PlayingSurfacePosition contains any objects which are both
     * 'blocking' and not dynamic, then returns the appropriate boolean.
     *
     * @param position A position to check.
     * @return Boolean indicating if position is blocked.
     */
    static public boolean isPositionPermanentlyBlocked(PlayingSurfacePosition position)
    {
        boolean permanentBlocker = false;

        for(IBoardObject object : position.getPositionObjects())
            if(object.isBlocking() && !(object instanceof IBoardObjectDynamic))
            {
                permanentBlocker = true;
                break;
            }

        return permanentBlocker;
    }

    /**
     * Checks if a PlayingSurfacePosition contains any objects which are of the
     * same type as a given object.
     *
     * @param position A position to check.
     * @param type A object whose type will be checked.
     * @return Boolean indicating if position contains object type.
     */
    static public boolean isPositionContainObject(PlayingSurfacePosition position, Object type)
    {
        boolean contains = false;

        for(IBoardObject object : position.getPositionObjects())
            if(object.getClass().getSimpleName().equals(type.getClass().getSimpleName()))
            {
                contains = true;
                break;
            }

        return contains;
    }
}
